﻿# -*- coding: UTF-8 -*- 
from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
import datetime

class Profile(models.Model):
    GENDER_CHOICES = (
        ('M', u'男'),
        ('F', u'女'),
    )
    
    JOB_CHOICES = (
        ('0', u'保密'),
        ('1', u'在校学生'),
        ('2', u'计算机/互联网/IT'),
        ('3', u'电子/半导体/仪表仪器'),
        ('4', u'通信技术'),
        ('5', u'销售'),
        ('6', u'市场拓展'),
        ('7', u'公关/商务'),
        ('8', u'采购/贸易'),
        ('9', u'客户服务/技术支持'),
        ('10', u'人力资源/行政/后勤'),
        ('11', u'高级管理'),
        ('12', u'生产/加工/制造'),
        ('13', u'质控/安检'),
        ('14', u'工程机械'),
        ('15', u'技工'),
        ('16', u'财会/审计/统计'),
        ('17', u'金融/证券/投资/保险'),
        ('18', u'房地产/装修/物业'),
        ('19', u'仓储/物流'),
        ('20', u'普通劳动力/家政服务'),
        ('21', u'普通服务行业'),
        ('22', u'航空服务业'),
        ('23', u'教育/培训'),
        ('24', u'咨询/顾问'),
        ('25', u'学术/科研'),
        ('26', u'法律'),
        ('27', u'设计/创意'),
        ('28', u'文学/传媒/影视'),
        ('29', u'餐饮/旅游'),
        ('30', u'化工'),
        ('31', u'能源/地质勘查'),
        ('32', u'医疗/护理'),
        ('33', u'保健/美容'),
        ('34', u'生物/制药/医疗器械'),
        ('35', u'体育工作者'),
        ('36', u'翻译'),
        ('37', u'公务员/国家干部'),
        ('38', u'私营业主'),
        ('39', u'农/林/牧/渔业'),
        ('40', u'武警/警察/消防/军人'),
        ('41', u'自由职业者'),
        ('42', u'其他'),
    )
    
    LOVE_STATUS_CHOICES = (
        ('0', u'保密'),
        ('1', u'单身'),
        ('2', u'恋爱'),
        ('3', u'已婚'),
    )
    
    SOCIAL_TARGET_CHOICES = (
        ('0', u'保密'),
        ('1', u'朋友'),
        ('2', u'异性朋友'),
        ('3', u'伴侣'),
    )
    
    user = models.ForeignKey(User, unique=True)
    #性别
    gender = models.CharField(max_length=1, choices=GENDER_CHOICES, default=u'M')
    #生日
    birthday = models.DateField(blank=True, null=True)
    #年龄(根据生日自动生成)
    age = models.SmallIntegerField(blank=True, null=True)
    #星座(根据生日自动生成)
    star_sign = models.CharField(max_length=10)
    #家乡
    hometown = models.CharField(max_length=128, default=u'')
    #居住地
    residence = models.CharField(max_length=128, default=u'')
    #职业
    job = models.CharField(max_length=2, choices=JOB_CHOICES, default=u'0')
    #单位或公司
    company = models.CharField(max_length=128, default=u'', blank=True)
    #毕业学校
    school = models.CharField(max_length=128, default=u'', blank=True)
    #爱情状态
    love_status = models.CharField(max_length=1, choices=LOVE_STATUS_CHOICES, default=u'0')
    #交友目的
    social_target = models.CharField(max_length=1, choices=SOCIAL_TARGET_CHOICES, default=u'0')    
    #联系方式#
    qq = models.CharField(max_length=15, default=u'')
    msn = models.EmailField(default=u'')
    gtalk = models.EmailField(default=u'')
    phone_number = models.CharField(max_length=50, default=u'')
    #blog或个人主页
    website = models.URLField(default=u'')
    #个人简介
    description = models.CharField(max_length=1000, default=u'')
    #头像(最小号的)
    logo = models.ImageField(upload_to="./upload", height_field=80, width_field=80)
    #状态签名
    status = models.CharField(max_length=72, default=u'')
    #状态签名最后更新时间
    last_update_status = models.DateTimeField(default=datetime.datetime.now)
    
    class Meta:
        db_table = 'profile'
        verbose_name = 'profile'
        verbose_name_plural = 'profiles'
        
def create_profile(sender, instance=None, **kwargs):
    if instance is None:
        return 
    profile, created = Profile.objects.get_or_create(user=instance)

post_save.connect(create_profile, sender=User)
